import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from agent import WindowAgent
import time

def main():
    agent = WindowAgent()
    
    # 示例1: 搜索并获取结果
    print("=== 搜索示例 ===")
    if agent.start_browser("chrome"):
        results = agent.browser_search(
            search_url="https://www.baidu.com",
            search_input_selector="#kw",
            search_text="Python自动化",
            result_selector="h3.t a",
            max_results=5
        )
        print(f"搜索结果: {results}")
        time.sleep(2)
        agent.close_browser()
    
    # 示例2: 保存登录信息
    print("\n=== 保存登录信息 ===")
    agent.start_browser("chrome")
    agent.browser_save_login(
        site_name="example_site",
        username="user@example.com",
        password="password123",
        login_url="https://example.com/login"
    )
    print("登录信息已保存")
    
    # 示例3: 自动登录（需要根据实际网站调整选择器）
    print("\n=== 自动登录示例 ===")
    # agent.browser_auto_login(
    #     site_name="example_site",
    #     username_selector="#username",
    #     password_selector="#password",
    #     submit_selector="#login-button"
    # )
    # time.sleep(3)
    
    agent.close_browser()

if __name__ == "__main__":
    main()
